package com.scu.baseline.service.impl;

import com.scu.baseline.mapper.HostMapper;
import com.scu.baseline.pojo.Host;
import com.scu.baseline.pojo.HostSimple;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (Host)表服务接口
 *
 * @author AlonBurukeses
 * @since 2022-06-14 17:24:32
 */
@Service
public class HostServiceImpl {
    @Resource
    private HostMapper hostmapper;
    /**
     * 通过ID查询单条数据
     *
     * @param hostId 主键
     * @return 实例对象
     */
    public List<Host> queryById(Integer hostId){

        return this.hostmapper.queryById(hostId);
    }



    /**
     * 新增数据
     *
     * @param host 实例对象
     * @return 实例对象
     */
    public void insert(Host host){
        this.hostmapper.insert(host);
    }
    public void insertMap(Host host){
        Map<String,Object> map = new HashMap<>();
        map.put("hostId",host.getHostId());
        map.put("hostName",host.getHostName());
        map.put("hostIpv4",host.getHostIpv4());
        map.put("hostOs",host.getHostOs());
        map.put("hostMac",host.getHostMac());
        map.put("hostOsBit",host.getHostOsBit());
        map.put("hostOsLanguage",host.getHostOsLanguage());
        map.put("hostOsCode",host.getHostOsCode());
        map.put("hostCpuNum",host.getHostCpuNum());
        map.put("hostCpuType",host.getHostCpuType());
        map.put("hostMainboardInc",host.getHostMainboardInc());
        map.put("hostMainboardId",host.getHostMainboardId());
        map.put("hostMainboardType",host.getHostMainboardType());
        map.put("hostMainboardStructure",host.getHostMainboardStructure());
        map.put("hostMemorySize",host.getHostMemorySize());
        map.put("hostCpuFrequency",host.getHostCpuFrequency());
        map.put("hostCpuCache",host.getHostCpuCache());
        map.put("hostCpuCore",host.getHostCpuCore());
        map.put("hostCpuWidth",host.getHostCpuWidth());

        this.hostmapper.insertMap(map);
    }
    public void insertMap(Map<String,Object> host){

        this.hostmapper.insertMap(host);
    }
    /**
     * 修改数据
     *
     * @param host 实例对象
     * @return 实例对象
     */
    public void update(Host host){

        Map<String,Object> map = new HashMap<>();
        map.put("hostId",host.getHostId());
        map.put("hostName",host.getHostName());
        map.put("hostIpv4",host.getHostIpv4());
        map.put("hostOs",host.getHostOs());
        map.put("hostMac",host.getHostMac());
        map.put("hostOsBit",host.getHostOsBit());
        map.put("hostOsLanguage",host.getHostOsLanguage());
        map.put("hostOsCode",host.getHostOsCode());
        map.put("hostCpuNum",host.getHostCpuNum());
        map.put("hostCpuType",host.getHostCpuType());
        map.put("hostMainboardInc",host.getHostMainboardInc());
        map.put("hostMainboardId",host.getHostMainboardId());
        map.put("hostMainboardType",host.getHostMainboardType());
        map.put("hostMainboardStructure",host.getHostMainboardStructure());
        map.put("hostMemorySize",host.getHostMemorySize());
        map.put("hostCpuFrequency",host.getHostCpuFrequency());
        map.put("hostCpuCache",host.getHostCpuCache());
        map.put("hostCpuCore",host.getHostCpuCore());
        map.put("hostCpuWidth",host.getHostCpuWidth());
        this.hostmapper.update(map);
    }
    public  void updateByMap(Map map){
        this.hostmapper.update(map);
    }

    /**
     * 通过主键删除数据
     *
     * @param hostId 主键
     * @return 是否成功
     */
    public boolean deleteById(Integer hostId){

        return this.hostmapper.deleteById(hostId);
    }
    public List<HostSimple> selectSimple(){

        return this.hostmapper.selectSimple();
    }
    public List<Host> selectHostByHostName(String hostName){
        return this.hostmapper.selectAllByHostNameHosts(hostName);
    }
    public List<HostSimple> selectHostSimpleByHostName(String hostName, Integer page){
        int tableCount = this.hostmapper.count();
        int pageCount = (tableCount - 1) / 10 + 1;
        int index = (page - 1) * 10;
        return this.hostmapper.selectByPage(index,hostName);
    }
    public List<HostSimple> selectHostSimplePaged(Integer page){
        int tableCount = this.hostmapper.count();
        int pageCount = (tableCount - 1) / 10 + 1;
        int index = (page - 1) * 10;
        return this.hostmapper.selectPage(index);
    }
    public HostSimple selectByHostMac(String hostMac){
        return this.hostmapper.selectByHostMac(hostMac);
    }
    public List<HostSimple> selectSimpleByHostId(Integer hostId){
        return this.hostmapper.selectSimpleByHostId(hostId);
    }
    public Integer count(){
        return this.hostmapper.count();
    }
    public List<HostSimple> selectSimpleByHostMac(String hostMac){
        return this.hostmapper.selectSimpleByHostMac(hostMac);
    }
}
